﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ConceptCorporateAdmin.Gui.Dialogs
{
    public partial class TipActNormativ : Form
    {
        public TipActNormativ()
        {
            InitializeComponent();
        }

        private void TipActNormativ_Load(object sender, EventArgs e)
        {
            
            DataTable dt = DbTipuriActeNormative.Instance.Table;
            List1.DataSource = dt;
            
            List1.DisplayMember = "Nume";
            List1.ValueMember   = "Id";
            
        }

        private void BtnAdauga_Click(object sender, EventArgs e)
        {
            String ret = InputBox.ShowMe("Adauga");
            if (!ret.Equals(""))
            {
                DbTipActNormativ act = new DbTipActNormativ();
                act.Nume = ret;
                act.CreateNew();
                refreshList();
            }

           
        }

        private void BtnSterge_Click(object sender, EventArgs e)
        {
            if (List1.SelectedValue != null)
            {
                DbTipActNormativ dbTip = new DbTipActNormativ();
                dbTip.Id = (int)List1.SelectedValue;
                dbTip.Delete();
                refreshList();
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            DbTipuriActeNormative.Instance.RefreshTable();
            List1.Refresh();
            this.Close();
        }

        private void Editeaza_Click(object sender, EventArgs e)
        {
            if (List1.SelectedValue != null)
            {
                int id = (int)List1.SelectedValue;
                DbTipActNormativ tip = new DbTipActNormativ();
                tip.getFromId(id);

                String ret = InputBox.ShowMe("Modifica", tip.Nume);
                if (!ret.Equals(""))
                {
                    tip.Nume = ret;
                    tip.Update();
                    refreshList();
                }
            }
        }

        private void refreshList()
        {
            DbTipuriActeNormative.Instance.RefreshTable();
            DataTable dt = DbTipuriActeNormative.Instance.Table;
            List1.DataSource = dt;

            List1.DisplayMember = "Nume";
            List1.ValueMember = "Id";

        }


     
    }
}
